#ifndef __GPU_H
#define __GPU_H

#include <config.h>
#include <types.h>
#include <gapi.h>

#define BPP_16	              16
#define BPP_24                24
#define MAX_LAYER_INDEX	      32

#define GPU_FB_SIZE           (0x00200000)

#define REG_CONTROL_LCD_EN    0x01
#define REG_CONTROL_MENU_EN   0x02
#define REG_CONTROL_VIDEO_EN  0x04
#define REG_CONTROL_GPU_EN    0x08
#define REG_CONTROL_INT_EN    0x10

#define REG_COMMAND_WRDISP    0x00	/* Tell GPU to write to display page (Data from GLT) */
#define REG_COMMAND_WRBUFSW   0x01	/* Tell GPU to write to buffer page, do switch (Data from GLT)*/
#define REG_COMMAND_WRBUF     0x02  /* Tell GPU to write to buffer page, do NOT switch (Data from GLT)*/
#define REG_COMMAND_SW        0x03  /* Tell GPU to switch display and buffer page */
#define REG_COMMAND_CAPDISP   0x04  /* Tell GPU to capture data on display page to specified address */
#define REG_COMMAND_CAPBUF    0x05  /* Tell GPU to capture data on buffer page to specified address */

#define GLT_DRAW_IMAGE        0x00
#define GLT_DRAW_LINE         0x01
#define GLT_DRAW_RECT_FRAME   0x02
#define GLT_DRAW_RECT_FILLED  0x03

/* GPU FB ioctl */
#define FBIOCTL_SET_CTRL        0x4620
#define FBIOCTL_GET_CTRL        0x4621
#define FBIOCTL_SET_CMD         0x4622
#define FBIOCTL_GET_CMD         0x4623
#define FBIOCTL_SET_LCDV        0x4624
#define FBIOCTL_GET_LCDV        0x4625
#define FBIOCTL_SET_LCDH        0x4626
#define FBIOCTL_GET_LCDH        0x4627
#define FBIOCTL_SET_LCDRES      0x4628
#define FBIOCTL_GET_LCDRES      0x4629
#define FBIOCTL_GET_STATUS      0x462A
#define FBIOCTL_SET_GLTIDX      0x462B
#define FBIOCTL_GET_GLTIDX      0x462C
#define FBIOCTL_SET_GLT         0x462D
#define FBIOCTL_GET_GLT         0x462E
#define FBIOCTL_GET_DISP_ADDR   0x462F
#define FBIOCTL_GET_BUF_ADDR    0x4630
#define FBIOCTL_SET_TPRATE      0x4631
#define FBIOCTL_GET_TPRATE      0x4632
#define FBIOCTL_SET_TPVALUE     0x4633
#define FBIOCTL_GET_TPVALUE     0x4634
#define FBIOCTL_SET_FBBASE0     0x4635
#define FBIOCTL_GET_FBBASE0     0x4636
#define FBIOCTL_SET_FBBASE1     0x4637
#define FBIOCTL_GET_FBBASE1     0x4638
#define FBIOCTL_SET_FBVGA2BASE  0x4639
#define FBIOCTL_GET_FBVGA2BASE  0x463A
#define FBIOCTL_GPU_WAIT        0x463B


/* Lines direction */
#define LINE_DIRECTION_LOWER_RIGHT 0x0
#define LINE_DIRECTION_LOWER_LEFT  0x1
#define LINE_DIRECTION_UPPER_RIGHT 0x2
#define LINE_DIRECTION_UPPER_LEFT  0x3


/* Transparent Rate for Menu and Video in*/
#define M50V50       0x0
#define M25V75       0x1
#define M12_5V87_5   0x2
#define M0V100       0x3
#define V50M50       0x4
#define M75V25       0x5
#define M87_5V12_5   0x6
#define M100V0       0x7

/* GPU relative functions */
inline void gpu_set_lcd_vert(u16 tvs, u16 tvp, u16 tve);
inline void gpu_set_lcd_hori(u16 ths, u16 thp, u16 the);
inline void gpu_set_lcd_res(u16 xr, u16 yr);
inline void gpu_set_tp_rate(u8 rate);
inline void gpu_set_tp_value(COLOR c);
inline char *gpu_get_fb_base(void);
void gpu_flush(s8 index, u8 cmd);
int gpu_draw_dot(DOT *dot);
int gpu_draw_line(LINE *line);
int gpu_draw_rect(RECT *rect);
int gpu_draw_image(IMAGE *image);
int gpu_capture_image(IMAGE *captured, BOOLEAN source);
void gpu_wait_busy(BOOLEAN);
inline void gpu_scale_image(IMAGE *image, s32 multiplier);
inline void gpu_scale_line(LINE *line, s32 multiplier);
inline void gpu_scale_rect(RECT *rect, s32 multiplier);
inline u32 gpu_current_disp_addr(void);
inline u32 gpu_current_buf_addr(void);
inline void gpu_switch_page(void);
inline u32 gpu_write_display(int fb);
inline u32 gpu_write_buffer(int fb, BOOLEAN sw);
inline u32 gpu_status(int fb);

#endif
